home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / misc / wexmast / wexclus.pro < prev    next >
Text File  |  1997-07-08  |  4KB  |  138 lines

  1. ; $Id: wexclus.pro,v 1.4 1997/01/15 04:29:15 ali Exp $
  2. ;
  3. ; Copyright (c) 1993-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. ; This is the code for an "exclusive" menu.
  7. ; This menu contains a list of values.  When a button is
  8. ; selected, any previously selected button is released, and
  9. ; the two values, new and old, are printed in the IDL
  10. ; window.  Selecting the 'Done' button destroys the widget.
  11.  
  12. ; An exclusive menu is a list of buttons in which only
  13. ; one button at a time can be selected.
  14.  
  15. ; For an example of a non-exclusive menu, see the routine
  16. ; WMENU.PRO.
  17.  
  18.  
  19.  
  20. PRO wexclus_event, event
  21.  
  22. ; This is the event handler for an exclusive menu.  The important
  23. ; part of this example is how a state is maintained by the menu.
  24.  
  25. ; The widgetblock common block is used because both wexclus and
  26. ; wexclus_event must know about all widgets that will generate values:
  27.  
  28. COMMON wexclusblock, menu_ids
  29.  
  30. ; The widgetstate common block provides access to the values which
  31. ; are used to by the event handler to set and maintain the state.
  32.  
  33. COMMON widgetstate, state_vals, current_state
  34.  
  35. ; Determine whether the menu selection came from the exclusive menu.
  36. ; If it did, set the example state based on the user value.
  37.  
  38. IF (where(tag_names(event) EQ 'VALUE'))[0] NE -1 THEN BEGIN
  39.  
  40. button_id = WHERE(menu_ids EQ event.value, count)
  41.  
  42. IF count GT 0 THEN BEGIN
  43.     ; Handle events from the exclusive menu.
  44.  
  45.     ; Save the old value of the state:
  46.     old_state = current_state
  47.  
  48.     ; Retrieve the new state from the user value of the selected
  49.     ; button and store it into the 'current_state' common variable:
  50.  
  51.     WIDGET_CONTROL, event.id, GET_UVALUE = state
  52.         current_state = state[button_id]
  53.  
  54.     print, 'Old State:    ', old_state
  55.     print, 'Current state:    ', current_state
  56.     print, ' '    ;new line
  57.  
  58. ENDIF
  59. ENDIF ELSE BEGIN
  60.  
  61.     WIDGET_CONTROL, event.id, GET_UVALUE = eventval
  62.  
  63.     CASE eventval OF
  64.         'DONE': WIDGET_CONTROL, event.top, /DESTROY
  65.     ENDCASE
  66. ENDELSE
  67.  
  68. END
  69.  
  70.  
  71.  
  72. PRO wexclus, GROUP=GROUP
  73.  
  74. ; This is the procedure that creates an exclusive button list using XMENU.
  75.  
  76. ; The COMMON block is used because both wexclus and wexclus_event must
  77. ; know about all widgets that will generate values:
  78.  
  79. COMMON wexclusblock, menu_ids
  80.  
  81. ; The widgetstate common block provides access to the values which
  82. ; are used to by the event handler to set and maintain the state.
  83.  
  84. COMMON widgetstate, state_vals, current_state
  85.  
  86. ; A top-level base widget with the title "Exclusive Buttons Example" will
  87. ; hold the exclusive buttons:
  88.  
  89. base = WIDGET_BASE(TITLE = 'Exclusive Buttons Example', $
  90.                   /COLUMN, $
  91.            XSIZE=300)
  92.  
  93. ; Set up the button labels.  The button labels will be used not only for
  94. ;the label on the button, but they will also be used for the user values
  95. ;of the buttons.
  96.  
  97. button_labels = ['Set State Value to 0.1', $
  98.                  'Set State Value to 0.2', $
  99.                  'Set State Value to 0.3']
  100.  
  101. ; Set up the values which represent the state which the exclusive menu
  102. ; governs.  Note that the uvalue array must be the same size as the
  103. ; value array.
  104.  
  105. state_vals = [0.1, 0.2, 0.3]
  106.  
  107. ; A widget called 'exclus' is created. It has the
  108. ; title: 'Exclusive Menu Widget' 
  109.  
  110. title = WIDGET_BASE(base,/FRAME, /COLUMN)
  111. label = WIDGET_LABEL(title, VALUE='Exclusive Button List')
  112. buttons = CW_BGROUP(title, button_labels, $
  113.                     IDS = menu_ids, $ ;The 'menu_ids' array holds the widget ID's for all buttons.
  114.                     /FRAME, /COLUMN, /NO_RELEASE, /RETURN_ID, $
  115.                     UVALUE = state_vals)
  116.  
  117. ; Make a 'DONE' button:
  118.  
  119. button1 = WIDGET_BUTTON(base, $
  120.                 UVALUE = 'DONE', $
  121.                 VALUE = 'DONE')
  122.  
  123. ; Realize the widgets:
  124. WIDGET_CONTROL, base, /REALIZE
  125.  
  126. ; Initialize the state maintained by the current_state variable:
  127. current_state = 0.1
  128.  
  129. ; Set the corresponding button to be pressed:
  130. WIDGET_CONTROL, menu_ids[0], /SET_BUTTON
  131.  
  132. ; Hand off control of the widget to the XMANAGER:
  133. XMANAGER, "wexclus", base, GROUP_LEADER=GROUP, /NO_BLOCK
  134.  
  135.  
  136. END
  137.  
  138.